package com.itqf.Service.Ordertopic.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.Dao.OrderMapper;
import com.itqf.Dao.OrdertopicMapper;
import com.itqf.Service.Ordertopic.OrderTopicService;
import com.itqf.entity.Order;
import com.itqf.entity.Ordertopic;
import com.itqf.entity.Shippingaddress;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderTopicServiceImpl implements OrderTopicService
{
    @Resource
    private OrdertopicMapper ordertopicMapper;
    @Resource
    private OrderMapper orderMapper;


    @Override
    public Ordertopic findordertopic(String orderid) {
        Ordertopic ordertopic = ordertopicMapper.selectByPrimaryKey(orderid);
        return ordertopic;
    }

    @Override
    public void insertordertopic(Ordertopic ordertopic) {
        ordertopicMapper.insert(ordertopic);
    }

    @Override
    public void updateordertopic(String orderid1, int topicInt, double v) {
        Map map=new HashMap();
        map.put("orderid",orderid1);
        map.put("topicInt",topicInt);
        map.put("totalprice",v);
        ordertopicMapper.updateordertopic(map);
    }

    @Override
    public void updateordertopicbyaddress(String orderid1, int shippingid) {
        Map map=new HashMap();
        map.put("orderid1",orderid1);
        map.put("shippingid",shippingid);
        ordertopicMapper.updateordertopicbyaddress(map);
    }

    @Override
    @Transactional
    public int updatebyordertopicid(String ordertopicid,String userid) {
        int a=ordertopicMapper.updatebyordertopicid(ordertopicid);
         Order order=new Order();
         order.setOrderid(ordertopicid);
         order.setUserid(userid);
         int b =orderMapper.insert(order);
         int paycode=0;
         if(a>0&&b>0)
         {
              paycode=200;
         }
         else {
              paycode=400;
         }
        return paycode;
    }
}
